package Queuedemo;

import java.util.Stack;

class MyQueue1 {
    Stack<Integer> stack1;
    Stack<Integer> stack2;

    public MyQueue1() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    //将元素放入队列中
    public void push(int x) {
        stack1.push(x);
    }

    //删除队列中元素并返回
    public int pop() {
        if(stack2.isEmpty()) {
            while(stack1.size() != 0) {
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }

    //返回队列开头的元素
    public int peek() {
        if(stack2.isEmpty()) {
            while(stack1.size() != 0) {
                stack2.push(stack1.pop());
            }
        }
        return stack2.peek();
    }

    //判断队列是否为空
    public boolean empty() {
        if(stack1.isEmpty() && stack2.isEmpty()) {
            return true;
        }
        return false;
    }
}